﻿<%@ Page Language="C#" MasterPageFile="~/master.master" %>

<%@ Import Namespace="DataAccess" %>
<script runat="server">
    [System.Web.Services.WebMethod]
    public static void LogDownload(string script)
    {
        script = script.Trim();
        if (!string.IsNullOrEmpty(script))
        {
            string[] scriptlist = script.Split(' ');
            SqlAccess sql = new SqlAccess();
            Guid transaction = Guid.NewGuid();
            foreach (string s in scriptlist)
                sql.InsertModel(new DownloadLog() { File = s, Downloaded = DateTime.Now, Transaction = transaction }, "DownloadLog", null, null, null);
        }
    }
    
</script>
<asp:Content ID="Content2" ContentPlaceHolderID="pagetitle" runat="Server">
    Download
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="pagemaincontent" runat="Server">
    <style type="text/css">
        #container
        {
            width: 420px;
            margin: auto;
        }
        #treeview
        {
            margin-top: 10px;
            margin-bottom: 5px;
            font-size: 140%;
        }
        #treeview td
        {
            padding: 4px;
        }
        
        #treeview div.sub
        {
            margin-left: 30px;
        }
        
        #treeview div.sub > table
        {
            width: 100%;
            margin-top: 7px;
        }
        #treeview div.sub > table .ibutton-container
        {
            margin-right: -7px;
        }
        
        #treeview > table
        {
            width: 100%;
            padding: 5px 45px 2px 5px;
            border-bottom: 3px solid #555;
        }
        #treeview hr
        {
            margin-top: 7px;
            margin-bottom: 17px;
            border: 1px dashed #555;
        }
        
        .treeviewparent
        {
            padding-top: 50px;
            border-top: 1px solid red;
        }
        .selectall
        {
            margin: 0px 70px;
            color: #969696;
            font-size: 17px;
        }
        #downloadbutton
        {
            margin-top: 60px;
        }
        
        .ibutton-container
        {
            float: right;
        }
        .ui-checkbox
        {
            margin-top: 7px;
            margin-right: 7px;
        }
    </style>
    <link rel="stylesheet" href="css/overcast/jquery-ui-1.8.20.custom.css" />
    <script type="text/javascript" src="js/jquery-ui-1.8.20.custom.min.js"></script>
    <link rel="stylesheet" href="css/checkbox.css" />
    <script type="text/javascript" src="js/ui.checkbox.js"></script>
    <link rel="stylesheet" href="css/jquery.ibutton.css" />
    <script type="text/javascript" src="js/jquery.ibutton.min.js"></script>
    <script type="text/javascript" src="jQueryClient/postback.js"></script>
    <script type="text/javascript">
        $(function () {
            $("input[type='checkbox'][name]").checkBox();
            $("input.ib").prop("checked", true);
            $(".selectall input[type='checkbox']").checkBox();
            $(".ib").iButton({
                labelOn: "Min",
                labelOff: "Debug"
            });
            $("input[type='button']").button();

            $("#treeview > table > tbody > tr > td:not(:first)").prepend("<hr/>");

            $("input:checkbox").prop("checked", true);

            $("#checkAll").click(function () {
                $("#treeview").find("input:checkbox[name]").prop("checked", $(this).is(':checked'));
            });

            $("#minAll").click(function () {
                $("input.ib").iButton("toggle", $(this).is(':checked'));   //.prop("checked", );
            });

            $("#treeview input:checkbox").click(function () {
                $(this).parent().find("div input:checkbox").prop("checked", $(this).is(':checked'));
                if (!$(this).is(':checked')) {
                    var parent = $(this).closest("div");
                    if (parent.attr('id') != 'treeview')
                        parent.parent().find("input:checkbox:first").prop("checked", false);
                }
            });
        });

        function getSriptName(sender) {
            if (sender.parent().find("> div.ibutton-container input.ib").is(':checked'))

                return sender.attr("name") + ".min ";
            else
                return sender.attr("name") + " ";
        }

        function downloadscript() {
            var script = "";

            $("#treeview input[type='checkbox'][name='pagination']:checked").each(function () {
                script += getSriptName($(this));
            });

            $("#treeview input[type='checkbox'][name='object']:checked").each(function () {
                script += getSriptName($(this));
            });

            $("#treeview input[type='checkbox'][name][name!='pagination'][name!='object']:checked").each(function () {
                script += getSriptName($(this));
            });

            $("#downloadpage").attr("src", "jsdownload.aspx?script=" + script);

            $.doPostback("LogDownload", { script: script });
        }


    </script>
    <iframe id="downloadpage" style="display: none"></iframe>
    <div id="container">
        <h3 title="">
            Build your download:
        </h3>
        <div id="treeview">
            <table>
                <tr>
                    <td>
                        <input id="checkbox-01" type="checkbox" name="postback" />
                        ajax postback<input type="checkbox" class="ib" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="Checkbox3" type="checkbox" name="databind" />
                        client repeater<input type="checkbox" class="ib" />
                        <div class="sub">
                            <table>
                                <tr>
                                    <td>
                                        <input id="Checkbox2" type="checkbox" name="jTemplates" />
                                        <a href="javascript:window.open('http://jtemplates.tpython.com/')">jTemplates</a><input
                                            type="checkbox" class="ib" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input id="Checkbox4" type="checkbox" name="pagination" />
                                        <a href="javascript:window.open('http://d-scribe.de/webtools/jquery-pagination/demo/demo_options.htm')">
                                            Pagination </a>
                                        <input type="checkbox" class="ib" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="Checkbox5" type="checkbox" name="object" />
                        Object helper<input type="checkbox" class="ib" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="Checkbox6" type="checkbox" name="dataformat" />
                        Type helper<input type="checkbox" class="ib" />
                        <div class="sub">
                            <table>
                                <tr>
                                    <td>
                                        <input id="Checkbox7" type="checkbox" name="datejs" />
                                        <a href="javascript:window.open('http://www.datejs.com/')">datejs</a><input type="checkbox"
                                            class="ib" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="selectall">
            <input id="checkAll" type="checkbox" />
            <span>Select/Deselet All</span>
            <br style="clear: both;" />
            <input id="minAll" type="checkbox" />
            <span>Compress/Decompress All</span><br style="clear: both;" />
            <p>
                Compressed by <a href="http://closure-compiler.appspot.com/">Closure Compiler</a></p>
        </div>
        <input id="downloadbutton" type="button" value="download the script" onclick="downloadscript()" />
    </div>
</asp:Content>
